﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Catalog
{
    public abstract class Catalog
    {
        static Catalog()
        {
            AvailableItems = new HashSet<CatalogItem>();
        }

        public static HashSet<CatalogItem> AvailableItems { get; private set; }

        public static string ShowAllItems()
        {
            return Catalog.ToString();
        }

        protected static void AddNewItem(CatalogItem item)
        {
            AvailableItems.Add(item);
        }

        protected static void RemoveItem(CatalogItem item)
        {
            AvailableItems.Remove(item);
        }

        static new string ToString()
        {
            StringBuilder result = new StringBuilder();

            if (AvailableItems.Count > 0)
            {
                result.AppendLine("All catalog items: ");

                foreach (var item in AvailableItems)
                {
                    result.AppendLine(string.Format("    {0}", item.ToString()));
                }
            }

            return result.ToString();
        }
    }
}